local skill = fk.CreateSkill {
  name = "mm__zhangjie",
}

skill:addEffect(fk.TurnEnd, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    return player:hasSkill(skill.name) and #player.room.logic:getActualDamageEvents(1, Util.TrueFunc, Player.HistoryTurn) ~= 0 
    and  ( ( player~=room.current and not room.current:isKongcheng() ) or player==room.current )
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:drawCards(1,skill.name)
    if player~=room.current then
      local pindian = player:pindian({room.current}, skill.name)
      if pindian.results[target].winner then
        local targets = {}
        room.logic:getActualDamageEvents(1, function(e) table.insertIfNeed(targets, e.data.to) end)
        targets = table.filter(targets, function(p) return not p.dead  end)
        for _, to in ipairs(targets) do
          to:drawCards(2,skill.name)
          if player.dead then return end
        end
      end
    else
      local targets = {}
        room.logic:getActualDamageEvents(1, function(e) table.insertIfNeed(targets, e.data.to) end)
        targets = table.filter(targets, function(p) return not p.dead and not p:isKongcheng() end)
        for _, to in ipairs(targets) do
          to:drawCards(2,skill.name)
          if player.dead then return end
        end
    end
    
    
  end,
})

Fk:loadTranslationTable{
  ["mm__zhangjie"] = "杖节",
  [":mm__zhangjie"] = "有角色受到伤害的回合结束时，你可以摸一张牌，然后你与当前回合角色拼点，若你赢或此时在你的回合内，本回合受到过伤害的角色依次摸两张牌。",
  ["$mm__zhangjie1"] = "吴汉联袂，当悌袍以待。",
  ["$mm__zhangjie2"] = "受主君之节，合累卵之隙。",
}
return skill